define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'rebate/batches/index' + location.search,
                    // add_url: 'rebate/batches/add',
                    // edit_url: 'rebate/batches/edit',
                    // del_url: 'rebate/batches/del',
                    multi_url: 'rebate/batches/multi',
                    import_url: 'rebate/batches/import',
                    table: 'rebate_batches',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('批次id')},
                        {field: 'period', title: __('期数'),operate:'='},
                        {field: 'triggered_at', title: __('Triggered_at'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'total_money', title: __('触发时总销售额'), operate:'BETWEEN'},
                        // {field: 'total_profit', title: __('Total_profit'), operate:'BETWEEN'},

                        {field: 'zijin_pool_before', title: __('触发前资金池金额'), operate:'BETWEEN'},
                        {field: 'zijin_pool_after', title: __('触发后资金池金额'), operate:'BETWEEN'},
                        {field: 'newprofit_before', title: __('触发前新增金额'), operate:'BETWEEN'},
                        {field: 'newprofit_after', title: __('触发后新增金额'), operate:'BETWEEN'},
                        
                        {field: 'is_manual', title: __('是否手动触发(0否 1是)')},
                        {field: 'actual_total_points', title: __('Actual_total_points')},
                        {field: 'scheduled_total_points', title: __('Scheduled_total_points')},
                        {field: 'required_profit', title: __('触发要求利润金额'), operate:'BETWEEN'},
                        // {field: 'users_affected', title: __('Users_affected')},
                        {field: 'dividend_before', title: __('Dividend_before'), operate:'BETWEEN'},
                        {field: 'dividend_after', title: __('Dividend_after'), operate:'BETWEEN'},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
